<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use \DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{

	public function getIndex(){
		$data=DB::table('user')->get();
		return view('form.form',['list'=>$data]);
	}

    public function getAdd(){
    	return view('form.add');
    }

    public function postInsert(Request $request){
    	$data=$request->except('_token');
    	DB::table('user')->insert($data);
    	return redirect('/index/index');
    }

    public function getEdit($id){
    	$data=DB::table('user')->where('id',$id)->first();
    	return view('form.edit',['list'=>$data]);
    }

    public function postUpdate(Request $request){
    	$data=$request->except('_token');
    	$str=DB::table('user')->where('id',$data['id'])->update($data);
    	if($str){
    		return redirect('index/index');
    	}else{
    		$request->flash();
    		return back();
    	}
    }

    public function getDel($id){
    	$data=DB::table('user')->where('id',$id)->delete();
    	if($data>0){
    		return redirect('/index/index');
    	}
    }

}
